package balmysundaycandy.more.low.level.operations.datastore.impl;

import java.util.concurrent.Future;

import balmysundaycandy.core.future.ProtocolMessageFuture;
import balmysundaycandy.core.operations.OperationNamespaces.datastore_v3;
import balmysundaycandy.more.low.level.operations.datastore.DatastoreOperation;

import com.google.apphosting.api.ApiProxy;
import com.google.apphosting.api.ApiProxy.ApiConfig;
import com.google.apphosting.api.DatastorePb.ActionRequest;
import com.google.apphosting.api.DatastorePb.ActionResponse;

/**
 * add action operation.
 * 
 * @author marblejenka
 */
public final class AddActionOperation extends DatastoreOperation<ActionRequest, ActionResponse> {

	@Override
	public ActionResponse call(ActionRequest request) {
		ActionResponse actionResponse = new ActionResponse();
		actionResponse.mergeFrom(ApiProxy.makeSyncCall(datastore_v3.packageName, datastore_v3.methodName.AddAction, request.toByteArray()));
		return actionResponse;
	}

	@Override
	public Future<ActionResponse> callAsync(ActionRequest request, ApiConfig apiConfig) {
		ActionResponse response = new ActionResponse();
		return new ProtocolMessageFuture<ActionResponse>(ApiProxy.makeAsyncCall(datastore_v3.packageName, datastore_v3.methodName.AddAction, request.toByteArray(), apiConfig),
				response);
	}
}